package com.project.bohang.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.project.bohang.common.model.Response;
import com.project.bohang.common.model.page.PageResult;
import com.project.bohang.entity.UserIsolate;
import com.project.bohang.pojo.dto.UserIsolateDto;
import com.project.bohang.pojo.vo.UserIsolateVo;
import com.project.bohang.service.UserIsolateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  隔离信息管理(管理员)
 *
 * @author bohang
 * @since 2022-03-27
 */
@Controller
@RequestMapping("/adminIsolate")
@ResponseBody
public class AdminIsolateController extends BaseController {

    @Autowired
    private UserIsolateService userIsolateService;

    /**
     * 隔离信息列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<PageResult<UserIsolateVo>> selectList(@RequestBody UserIsolateDto dto){
        return Response.success(getDataTable(userIsolateService.selectList(dto)));
    }

    /**
     * 新增隔离信息
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody UserIsolate req) {
        userIsolateService.save(req);
        return Response.success();
    }


    /**
     * 修改隔离信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody UserIsolate req) {
        UpdateWrapper<UserIsolate> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        userIsolateService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除隔离信息
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody UserIsolate req) {
        UserIsolate entity = new UserIsolate();
        entity.setId(req.getId());
        entity.setDeleted("1");
        userIsolateService.updateById(entity);
        return Response.success();
    }

    /**
     * 隔离信息详情
     *
     * @param req
     * @return
     */
    @PostMapping("/detail")
    public Response<UserIsolate> detail(@RequestBody UserIsolate req) {
        UserIsolate entity = userIsolateService.getById(req.getId());
        return Response.success(entity);
    }


}

